package www.dianbaozu.com.ui.my

import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import www.dianbaozu.com.R
import www.dianbaozu.com.databinding.FragmentCancelledBinding
import www.wen.com.common.lib.base.fragment.BaseLoadingFragment
import www.wen.com.common.lib.base.module.BaseViewModel
import www.wen.com.common.lib.extension.resetStartDestination
import www.wen.com.common.lib.helper.loading.TitleBarUniversalAdapter

/**
 * @author WEN
 * @Description: 账号注销
 * @date 2020//25 17:48
 */
@AndroidEntryPoint
class CancelledFragment : BaseLoadingFragment<FragmentCancelledBinding>(), View.OnClickListener{

    private val mBaseApiViewModel: ContractViewModel by viewModels()

    override val viewModel: BaseViewModel
        get() = mBaseApiViewModel

    override fun isEnableLoadingHelper(): Boolean = true

    override fun getTitleBarUniversalAdapter(): TitleBarUniversalAdapter = TitleBarUniversalAdapter(requireActivity(),"注销账户", action = ::titleAction)

    override fun getLayoutId(): Int = R.layout.fragment_cancelled

    override fun lazyInitView() {
        addBackPressedCallBack()
    }

    override fun actionLeft() {
        requireActivity().resetStartDestination(R.navigation.navigation, R.id.loginFragment)
    }

    /**
     * 返回键直接关闭该页面
     */
    private fun addBackPressedCallBack() {
        requireActivity().onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {

            override fun handleOnBackPressed() {
                requireActivity().resetStartDestination(R.navigation.navigation, R.id.loginFragment)
            }
        })
    }

    override fun onClick(v: View) {
        requireActivity().resetStartDestination(R.navigation.navigation, R.id.loginFragment)
    }

}



